<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>
</template>
<script>
import {_config, _href} from "@/js/s94_tool.js";
import {iframe, in_right_admin} from "@/js/tool.js";
import s94Mjs from "s94-js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    if(in_right_admin('UserWithdraw/add')) btns['添加'] = function(){ iframe('user_withdraw/edit') }
    if(in_right_admin('UserWithdraw/export')) btns['导出'] = function(){
      let param = s94Mjs.param_encode(app.$refs['list_url'].$refs['forms'].form_data());
      window.open(_href("/admin/user_withdraw/export?"+param), '_blank')
    }


    let type_map = _config('status_alias_map.user_withdraw.type');
    let status_config = _config('status_alias_map.user_withdraw.status');
    let forms_config = {
      add_time: {label:'申请时间',name:'where[create_time][between]',config:'Y-M-D',type:'date_between',value:''},
      withdraw_time: {label:'提现时间',name:'where[withdraw_time][between]',config:'Y-M-D',type:'date_between',value:''},
      user_phone: {label:'用户手机号/昵称',name:'where[user.phone|user.nickname][like]',type:'text_one',value:''},
      user_id: {label:'用户',name:'where[user_id][eq]',type:'list_id',no_table:1,config:'user/index',value:this.$get('user_id','')},
      status: {label:'状态',name:'where[status][eq]',type:'select_one',config:status_config,value:''},
    };
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left', type: 'hidden', order:true},
      head_img: {name:'head_img', label:'头像', width:'60px', type:'file_img'},
      phone:{name:'phone', label:'电话号码',  width:'120px'},
      nickname:{name:'nickname', label:'昵称', width:'120px'},
      money:{name:'money', label:'提现金额', width:'75px'},
      service_money:{name:'service_money', label:'手续费', width:'75px'},
      withdraw_money:{name:'withdraw_money', label:'到账金额', width:'75px'},
      type:{name:'type', label:'提现类型', width:'70px',type:'select_one',config:type_map},
      note_user:{name:'note_user', label:'用户备注'},
      status:{name:'status', label:'状态', width:'75px',type:'select_one',config:status_config},
      withdraw_time:{name:'withdraw_time', label:'提现时间', width:'165px'},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'创建时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'80px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/user_withdraw/'+(is_del?'recycle':'list'),
        title: "提现申请列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
        order: 'status asc',
      },
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('UserWithdraw/edit') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      can_edit = can_edit && row.status==0;
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('user_withdraw/edit?'+s94Mjs.param_encode(param))
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
